﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>系统菜单</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/qmsk-1.2.js"></script>
<script type="text/javascript" src="../js/commonSelecter.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
var _pagination = null;
/**
 * 入口，和服务器的通信从此开始
 */
$(function() {
	refreshInput($(".serWrapper"));
});

/**
 * 为查找做准备，这里主要是生成查询条件对象
 */
function toSearch() {
	$("#functionTable").empty();
	var pId = $("#SelectParent").val();
	var name = $("#goodsLrNm").val();
	if(IsEmpty(pId)){
		pId = "";
	}
	_pagination = new Pagination({
		url : '../func/find/opt/',
		data : {
			name : name,
			pId : pId
		},
		success : printDataToPage,
		pageSize : 10
	});
}

/**
 * 删除一行
 */
function toDelete(id,row) {
	if (IsEmpty(id)) {
		artError('未获取到主要信息！');
		return false;
	}
	
	//直接发出请求
	artConfirm("岗位权限与其同步删除,确认删除吗？", function() {
		qmsk.post("../func/del",{'id' : id}, function(rst) {
			artSuccess("删除成功！");
			toSearch();
		});
	});
}


function printDataToPage(message){
	var oldBillNo = null;
	dataTable({
		tbodyId : 'functionTable',
		heads : ["code", "name", "url", ["pId","id"]],
		rst : message,
		handler : [{
			col : 3,
			f : detail
		}],
		sup : {
			id : "sup",
			template : "共 [index] 条"
		}
	});
}

/**
 * 隐藏添加弹出层
 */
function hideAddPanel() {
	$("#window_change,#yinying1").hide();
}

/**
 * 隐藏添加弹出层
 */
function hideAddPanel1() {
	$("#window_change1,#yinying1").hide();
}

function toAdd(isParent){
	$("#addUrl").val("");
	$("#addName").val("");
	$("#addCode").val("");
	if(isParent == 0){
		$("#url_1").hide();
		$("#p_1").hide();
		$("#parent").val(0);
	}else{
		$("#p_1").show();
		$("#url_1").show();		
		$("#parent").val(1);
	}
	$("#window_change,#yinying1").show();
	addMargin($("#window_change"));
}

/* function toAddParent(){
	$("#addPUrl").val("");
	$("#addPName").val("");
	$("#window_change,#yinying1").show();
	addMargin($("#window_change2"));
} */

function toEdit(id,pid){
	$("#editParent").html("");
	if(pid == 0){
		$("#p_2").hide();
		$("#url_2").hide();
		$("#parent").val(0);
	}else{
		$("#p_2").show();
		$("#url_2").show();		
		$("#parent").val(1);
	}
	$("#window_change1,#yinying1").show();	
	addMargin($("#window_change1"));
	var rst = _findInfo("../func/find/id",{"id":id});
	if (IsNotEmpty(rst)){
		$("#editUrl").val(getHtmlString(getHeadIndexValue(0,rst,'url')));
		$("#editName").val(getHtmlString(getHeadIndexValue(0,rst,'name')));
		$("#editCode").val(getHtmlString(getHeadIndexValue(0,rst,'code')));
		$("#lgId").val(getHtmlString(getHeadIndexValue(0,rst,'id')));
		var pId = getHtmlString(getHeadIndexValue(0,rst,'pId'));
		if(IsNotEmpty(pId) && pId > 0){
			rstg = _findInfo("../func/find/id",{"id":pId});
			var id = getHtmlString(getHeadIndexValue(0,rstg,'id'));
			var name =  getHtmlString(getHeadIndexValue(0,rstg,'name'));

			$("#editParent").html("<option value='" + id + "' selected=\"selected\" >" + name + "</option>");
		}
	}
}

function edit(){
	var parent = $("#parent").val();
	var url = $("#editUrl").val();
	var name = $("#editName").val();
	var code = $("#editCode").val();
	var id = $("#lgId").val();
	if(IsEmpty(id)){
		art.dialog({fixed:true, lock: true,content:"id未找到",icon:'error',ok:true});	
		return false;
	}
	var parentId = $("#editParent").val();
	
	if(parent == 1){
		if(IsEmpty(url)){
			art.dialog({fixed:true, lock: true,content:"url不能为空",icon:'error',ok:true});	
			return false;
		}
		
		if(IsEmpty(parentId)){
			art.dialog({fixed:true, lock: true,content:"主菜单未选择",icon:'error',ok:true});	
			return false;
		}
	}else{
		parentId = 0;
	}
	
	if(IsEmpty(url)){
		url = "";
	}
	
	if(IsEmpty(name)){
		art.dialog({fixed:true, lock: true,content:"名称不能为空",icon:'error',ok:true});	
		return false;
	}
	var heads = new Array("name","code", "url","pId", "id");
	var datas = new Array(name, code, url,parentId, id);
	
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "edit" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	
	qmsk.post("../func/edit", {
		data : jsonParserStr
	}, function() {
		artSuccess("修改成功！");
		hideAddPanel1();
		if (_pagination) {
			_pagination.reload();
		}
	});
}

function add() {
	var parent = $("#parent").val();
	var url = $("#addUrl").val();
	var name = $("#addName").val();
	var code = $("#addCode").val();
	if(IsEmpty(name)){
		art.dialog({fixed:true, lock: true,content:"名称不能为空",icon:'error',ok:true});	
		return false;
	}
	
	var parentId = $("#addParent").val();
	if(parent == 1){
		if(IsEmpty(url)){
			art.dialog({fixed:true, lock: true,content:"url不能为空",icon:'error',ok:true});	
			return false;
		}
		
		if(IsEmpty(parentId)){
			art.dialog({fixed:true, lock: true,content:"主菜单未选择",icon:'error',ok:true});	
			return false;
		}
	}else{
		parentId = 0;
	}
	
	if(IsEmpty(url)){
		url = "";
	}
	
	var heads = new Array("name","code","pId","url");
	var datas = new Array(name,code,parentId,url);
	
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "add" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	
	qmsk.post("../func/insert", {
		data : jsonParserStr
	}, function() {
		artSuccess("添加成功！");
		hideAddPanel();
		toSearch();
	});
}

function detail(heads, row){
	return	"<input class='del common_btn' type='button' value='删除' onclick='toDelete("+heads[1]+","+row+")'>"+"<input class='edit common_btn' type='button' value='修改' onclick='toEdit("+heads[1]+","+heads[0]+")'>";
}

function initSelectFunctionParent(){
	$("#SelectParent").blur();
	initSelecter({
		url : '../func/find/pId',
		heads : ["code", "name"],
		titles : ["编码", "主菜单名称"],
		zindex : 500,
		callBack : callBack1
	});
}

function callBack1(response, row) {
	var id = response.getValue('id', row);
	var name = response.getValue('name', row);
	$("#SelectParent").html("<option value='" + id + "' selected=\"selected\" >" + name + "</option>");
}

function initFunctionParent(){
	$("#editParent").blur();
	$("#addParent").blur();
	initSelecter({
		url : '../func/find/pId',
		heads : ["code", "name"],
		titles : ["编码", "主菜单名称"],
		zindex : 500,
		callBack : callBack
	});
}

function callBack(response, row) {
	var id = response.getValue('id', row);
	var name = response.getValue('name', row);
	$("#editParent").html("<option value='" + id + "' selected=\"selected\" >" + name + "</option>");
	$("#addParent").html("<option value='" + id + "' selected=\"selected\" >" + name + "</option>");
}


</script>
</head>

<body>
		<div id="yinying"></div>
		<div id="yinying1"></div>
		<!-- 添加记录 弹出层 -->
		<div id="window_change" class="member_search hideDiv">
			<div class="closeTop">
				<span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span>
			</div>
			<p>
				<label style="margin-left:140px"><span>系统菜单编码：</span>
					<input type="text" id="addCode" class="absoluteTxt">
				</label>
				<label style="margin-left:140px"><span>系统菜单名称：</span>
					<input type="text" id="addName" class="absoluteTxt">
				</label>
				<label id="p_1" style="margin-left:140px"><span>系统菜单名称：</span>
					<select id="addParent" onclick="initFunctionParent()"></select>
				</label>
				<label id="url_1" style="margin-left:143px"><span>系统菜单url：</span>
					<input type="text" id="addUrl" class="absoluteTxt">
				</label>
			</p>

			<div class="submit_btn">
				<input type="button" value="保存信息" class="common_btn" id="saveButton" onclick="add()">
			</div>
		</div>
		<input type="hidden" id="parent" />
		
<!-- 		<div id="window_change2" class="member_search hideDiv">
			<div class="closeTop">
				<span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span>
			</div>
			<p>
				<label style="margin-left:140px"><span>系统菜单编码：</span>
					<input type="text" id="addPCode" class="absoluteTxt">
				</label>
				<label style="margin-left:140px"><span>系统菜单名称：</span>
					<input type="text" id="addPName" class="absoluteTxt">
				</label>
			</p>
			<div class="submit_btn">
				<input type="button" value="保存信息" class="common_btn" id="saveButtonParent" onclick="toAddParent()">
			</div>
		</div> -->
		
		<div id="window_change1" class="member_search hideDiv">
			<div class="closeTop">
				<span class="closeThe" onclick="closeParent($(this))"><img src="../images/close.png"></span>
			</div>
			<p>
				<label style="margin-left:140px"><span>系统菜单编码：</span>
					<input type="text" id="editCode" class="absoluteTxt">
				</label>
				<label style="margin-left:140px"><span>系统菜单名称：</span>
					<input type="text" id="editName" class="absoluteTxt">
					<input type="hidden" id="lgId">
				</label>
				
				<label id="p_2" style="margin-left:140px"><span>系统菜单名称：</span>
					<select id="editParent" onclick="initFunctionParent()"></select>
				</label>
				<label id="url_2" style="margin-left:143px"><span>系统菜单url：</span>
					<input type="text" id="editUrl" class="absoluteTxt">
				</label>
			</p>

			<div class="submit_btn">
				<input type="button" value="保存信息" class="common_btn" id="editButton" onclick="edit()">
			</div>
		</div>

<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">系统菜单</div>
    <div class="member_search">
      <p><span>
         菜单名称：<input type="text" id="goodsLrNm" class="absoluteTxt"></span>
         <span>
         主菜单名称：<select id="SelectParent" onclick="initSelectFunctionParent()"></select></span>
        <span><input type="button" value="查询" class="btn" onclick="toSearch()"></span>
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>系统菜单列表 <span id="sup">共0条</span></strong>
       <input type="button" class="common_btn" value="新增主菜单" id="addColumn" onclick="toAdd(0)">
      	<input type="button" class="common_btn" value="新增子菜单" id="addColumn1" onclick="toAdd(1)">
      </caption>
      <thead>
        <tr>
          <th>编码</th>
          <th>系统菜单名称</th>
          <th>菜单路径</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody id="functionTable">
      
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager" class="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
